<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/core.php');

$distribute = new Distribute($_GET['id']);

$setting = $distribute->getStoreSetting();

    if(!Distribute::$config['presonal_store_open']){
        echo "<script>history.back();</script>";
        exit;
    }

?><!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo $setting['name'];?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="full-screen" content="yes"/>
    <meta name="browsermode" content="application"/>
    <!-- QQ强制竖屏 QQ强制全屏 -->
    <meta name="x5-orientation" content="portrait"/>
    <meta name="x5-fullscreen" content="true"/>
    <meta name="x5-page-mode" content="app"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../css/reset.css">
    <link rel="stylesheet" type="text/css" href="../../css/main.css">
    <link rel="stylesheet" type="text/css" href="../../css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/member.css">
    <link rel="stylesheet" type="text/css" href="/wap/css/phone.css"/>
    <style>
        #bottom .nav{
            background: #444;
        }
        header, .header, .header-wrap{
            background:#f8f8f8 !important;
        }
    </style>
    <script type="text/javascript" src="../../js/config.js"></script>
    <script type="text/javascript" src="/wap/js/jquery.min.js"></script>

<!--    <script type="text/javascript" src="../../js/zepto.min.js"></script>-->
    <script type="text/javascript" src="../../js/template.js"></script>
    <script src="/wap/js/layer.m/layer.m.js" ></script>
    <script type="text/javascript" src="../../js/common.js"></script>
</head>
<body>
    <header id="header"></header>

    <div class="touch"></div>
    <style>
        body{
            overflow: auto !important;
        }
        .banner{
            overflow-x: scroll !important;
            overflow-y: hidden;
            width : 100%;
        }
        .banner img{
            width : 100%;
            float: left;
        }
        header{
            height: 50px !important;
        }
        .header-back{
            top: 4px !important;
        }
    </style>
    <div class="banner">
        <iframe src="" width='100%' frameborder="0"></iframe>
        <?php
        $imglist = array();
        for ($i = 0; $i < 3; $i++) {
            if (!empty($setting['img' . ($i + 1)])) {
                $imglist[] = $setting['img' . ($i + 1)];
        ?>
                <!-- <img src="<?php echo $setting["img" . ($i + 1)] ?>" alt=""/> -->
        <?php
            }
        }

        ?>
    </div>
    <script>
        var imglist = <?php echo json_encode($imglist)?>;

        var base_width = $('.banner').width();
        var base_height = base_width * 0.618;
        $('.banner iframe').height(base_height);
        var dom = $('iframe')[0].contentDocument;
        var box = dom.body;
        box.style.width = (base_width * imglist.length) + 'px';
        var style = '<style>*{margin:0;padding:0;} img{float:left;} body{overflow-y:hidden;} ::-webkit-scrollbar{width:0;height:0;visibility: hidden;background: rgba(0,0,0,0)} </style>';
        box.innerHTML = style;
        imglist.forEach(function(item){
            var img = dom.createElement("img");
            img.src = item;
            img.width = base_width;
            img.height = base_height;
            box.appendChild(img);
        });
        setInterval(function(){
            var count = parseInt($(box).scrollLeft() / base_width);
            console.log(count);
            if(count++ >= imglist.length - 1){
                count = 0;
            }
            $(box).animate({
                scrollLeft : count * base_width
            });

        },3000);
    </script>

    <link rel="stylesheet" type="text/css" href="/wap/css/index.css">

    <div id="goods_list" class="main">
        <div class="index_block goods">
            <div class="content">
                <?php
                $distribute = new Distribute($_GET['id']);
                $goods = $distribute->getAllGoods();
                foreach ($goods as $good) {
                    $ginfo = ml('goods')->where('goods_commonid = ' . $good['goods_commonid'])->find();
                    ?>
                    <div class="goods-item">
                        <a href="/wap/tmpl/product_detail.html?goods_id=<?php echo $ginfo['goods_id']?>">
                            <div class="goods-item-pic"><img src="<?php echo thumb($ginfo)?>" alt="" style=""></div>
                            <div class="goods-item-name"><?php echo $ginfo['goods_name'];?></div>
                            <div class="goods-item-price">
                                ￥<?php echo $ginfo['goods_price']?>
                                <div class="ext">
                                    <?php
                                    if ($good['open_tax'] == 1) {
                                    ?>
                                        <span class="ext">保税</span>
                                    <?php
                                    }
                                    $sinfo = ml('store')->find($ginfo['store_id']);
                                    if($sinfo['is_own_shop'] == 1){
                                    ?>
                                        <span class="ext">自营</span>
                                        <?php
                                    }
                                    ?>
                                </div>

                            </div>
                        </a>
                    </div>
                    <?php
                }
                ?>
            </div>
        </div>

    </div>

    <footer id="footer"></footer>
    <script type="text/javascript" src="../../js/tmpl/common-top.js"></script>
    <!-- <script>alert(2)</script> -->
    <script type="text/javascript" src="../../js/tmpl/footer.js"></script>

    <script type="text/javascript" src="../../js/tmpl/member.js"></script>
    <script>
        $('.goods-item-pic').each(function () {
            $(this).height($(this).width());
        })
    </script>

    <?php
        require_wechat_js();
    ?>
    <script>
        var share_data = {
            title: '<?php echo $setting['name']?>', // 分享标题
            desc: '', // 分享描述
            link: '<?php echo "http://" . $_SERVER['HTTP_HOST'] . "/wap/tmpl/member/distribute_store.php?id=" . $distribute->getMemberId() . "&uid=" . $distribute->getMemberId()?>', // 分享链接
            imgUrl: '<?php echo  empty($imglist[0]) ? getMemberAvatarForID($distribute->getMemberId()) : 'http://' . $_SERVER['HTTP_HOST'] . $imglist[0] ?>', // 分享图标
            type: '', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                // 用户确认分享后执行的回调函数
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        };

        wx.ready(function () {
            wx.onMenuShareTimeline(share_data);
            wx.onMenuShareAppMessage(share_data);
            wx.onMenuShareQQ(share_data);
            wx.onMenuShareWeibo(share_data);
            wx.onMenuShareQZone(share_data);
        })

//        $('.user_top dt img').bind('load',function() {
//            share_data.imgUrl = '<?php //echo "http://" . $_SERVER['HTTP_HOST'] . '/'?>//' + $('.user_top dt img').attr('src');
//        })
    </script>
</body>
</html>